<template>
    <el-form :model="peradd" label-width="auto" style="max-width: 600px;margin-left: 200px;">
        <div>
            <H1 style="margin-left: 200px;">编辑权限</H1>
        </div>

        <el-form-item label="权限名称:">
            <el-input v-model="peradd.permissionName" />
        </el-form-item>
        <el-form-item label="权限URL:">
            <el-input v-model="peradd.permissionURL" />
        </el-form-item>
        <el-form-item label="权限序号:">
            <el-input v-model="peradd.index" />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">保存</el-button>
            <el-button @click="bient">返回</el-button>
        </el-form-item>
    </el-form>
</template>

<script lang="ts" setup>
import { reactive, ref, onMounted } from 'vue'
import { Read, Write } from '@/Http/axios'
import { ElMessage, ElMessageBox } from "element-plus";
import { useCounterStore } from '@/stores/counter';
import router from '@/router'
import { useRoute } from 'vue-router';
const route = useRoute();
const store = useCounterStore();

const peradd = reactive({
    "permissionId": <any>0,
    "permissionName": "",
    "permissionURL": "",
    "index": 0
})

const onSubmit = () => {
    peradd.permissionId = route.query.permissionId
    Write.post("/Management/UpdatePer", peradd).then(res => {
        if (res.data.code == 400) {
            ElMessage.success("修改成功")
            router.push('/PermissionShow')
        }
        else {
            ElMessage.error("修改失败")
        }
    }).catch(err => {
        console.log(err)
    })
}

const periddata = ref([

])

const peridlist = () => {
    let permissionId = route.query.permissionId
    Read.get("/Management/SetPermission", {
        params: {
            PermissionId: permissionId
        }
    }).then(res => {
        peradd.permissionName = res.data.data[0].permissionName
        peradd.permissionURL = res.data.data[0].permissionURL
        peradd.index = res.data.data[0].index
    }).catch(err => {
        console.log(err)
        ElMessage.error("查询失败")
    })
}
//钩子函数
onMounted(() => {
    peridlist();
})
//返回
const bient = () => {
    router.push('/PermissionShow')
}


</script>
